package com.heima.wemedia.controller.v1;

import com.heima.common.constants.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Xiao
 * @version 1.0
 * @description
 * @date 2021/11/21
 */
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService materialService;

    /**
     * 素材管理-图片上传
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {
        return materialService.uploadPicture(multipartFile);
    }

    /**
     * 素材管理-素材列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return materialService.getListMaterial(dto);
    }

    /**
     * 素材管理-收藏/取消收藏
     * @param collect
     * @param id
     * @return
     */
    @GetMapping("/{collect}/{id}")
    public ResponseResult isCollection(@PathVariable("collect") String collect,
                                  @PathVariable("id") Integer id) {
        Integer isCollection = "collect".equals(collect) ?
                WemediaConstants.COLLECT_MATERIAL : WemediaConstants.CANCEL_COLLECT_MATERIAL;
        return materialService.isCollection(id, isCollection);
    }

    /**
     * 素材管理-删除素材
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable Integer id) {
        return materialService.delPicture(id);
    }
}
